home *** CD-ROM | disk | FTP | other *** search
/ Champak 146 / (Vol 146) Jan 07 2012.iso / Interface / it.dig / scripts / __Packages / mx / controls / ComboBox.as < prev    next >
Encoding:
Text File  |  2012-01-07  |  13.6 KB  |  485 lines

  1. class mx.controls.ComboBox extends mx.controls.ComboBase
  2. {
  3.    var __labels;
  4.    var data;
  5.    var __dropdownWidth;
  6.    var __width;
  7.    var selectedIndex;
  8.    var __dropdown;
  9.    var dataProvider;
  10.    var __labelFunction;
  11.    var owner;
  12.    var mask;
  13.    var border_mc;
  14.    var text_mc;
  15.    var getValue;
  16.    var length;
  17.    var selectedItem;
  18.    var isPressed;
  19.    var dispatchEvent;
  20.    var __dataProvider;
  21.    var selected;
  22.    static var symbolName = "ComboBox";
  23.    static var symbolOwner = mx.controls.ComboBox;
  24.    static var version = "2.0.0.377";
  25.    var clipParameters = {labels:1,data:1,editable:1,rowCount:1,dropdownWidth:1};
  26.    static var mergedClipParameters = mx.core.UIObject.mergeClipParameters(mx.controls.ComboBox.prototype.clipParameters,mx.controls.ComboBase.prototype.clipParameters);
  27.    var className = "ComboBox";
  28.    var _showingDropdown = false;
  29.    var __rowCount = 5;
  30.    var dropdownBorderStyle = undefined;
  31.    var initializing = true;
  32.    var __labelField = "label";
  33.    var bInKeyDown = false;
  34.    function ComboBox()
  35.    {
  36.       super();
  37.    }
  38.    function init()
  39.    {
  40.       super.init();
  41.    }
  42.    function createChildren()
  43.    {
  44.       super.createChildren();
  45.       this.editable = this.editable;
  46.       if(this.__labels.length > 0)
  47.       {
  48.          var _loc6_ = new Array();
  49.          var _loc3_ = 0;
  50.          while(_loc3_ < this.labels.length)
  51.          {
  52.             _loc6_.addItem({label:this.labels[_loc3_],data:this.data[_loc3_]});
  53.             _loc3_ = _loc3_ + 1;
  54.          }
  55.          this.setDataProvider(_loc6_);
  56.       }
  57.       this.dropdownWidth = typeof this.__dropdownWidth != "number" ? this.__width : this.__dropdownWidth;
  58.       if(!this._editable)
  59.       {
  60.          this.selectedIndex = 0;
  61.       }
  62.       this.initializing = false;
  63.    }
  64.    function onKillFocus(n)
  65.    {
  66.       if(this._showingDropdown && n != null)
  67.       {
  68.          this.displayDropdown(false);
  69.       }
  70.       super.onKillFocus();
  71.    }
  72.    function getDropdown()
  73.    {
  74.       if(this.initializing)
  75.       {
  76.          return undefined;
  77.       }
  78.       if(!this.hasDropdown())
  79.       {
  80.          var _loc3_ = new Object();
  81.          _loc3_.styleName = this;
  82.          if(this.dropdownBorderStyle != undefined)
  83.          {
  84.             _loc3_.borderStyle = this.dropdownBorderStyle;
  85.          }
  86.          _loc3_._visible = false;
  87.          this.__dropdown = mx.managers.PopUpManager.createPopUp(this,mx.controls.List,false,_loc3_,true);
  88.          this.__dropdown.scroller.mask.removeMovieClip();
  89.          if(this.dataProvider == undefined)
  90.          {
  91.             this.dataProvider = new Array();
  92.          }
  93.          this.__dropdown.setDataProvider(this.dataProvider);
  94.          this.__dropdown.selectMultiple = false;
  95.          this.__dropdown.rowCount = this.__rowCount;
  96.          this.__dropdown.selectedIndex = this.selectedIndex;
  97.          this.__dropdown.vScrollPolicy = "auto";
  98.          this.__dropdown.labelField = this.__labelField;
  99.          this.__dropdown.labelFunction = this.__labelFunction;
  100.          this.__dropdown.owner = this;
  101.          this.__dropdown.changeHandler = this._changeHandler;
  102.          this.__dropdown.scrollHandler = this._scrollHandler;
  103.          this.__dropdown.itemRollOverHandler = this._itemRollOverHandler;
  104.          this.__dropdown.itemRollOutHandler = this._itemRollOutHandler;
  105.          this.__dropdown.resizeHandler = this._resizeHandler;
  106.          this.__dropdown.mouseDownOutsideHandler = function(eventObj)
  107.          {
  108.             if(!this.owner.hitTest(_root._xmouse,_root._ymouse,false))
  109.             {
  110.                if(!(!this.wrapDownArrowButton && this.owner.downArrow_mc.hitTest(_root._xmouse,_root._ymouse,false)))
  111.                {
  112.                   this.owner.displayDropdown(false);
  113.                }
  114.             }
  115.          };
  116.          this.__dropdown.onTweenUpdate = function(v)
  117.          {
  118.             this._y = v;
  119.          };
  120.          this.__dropdown.setSize(this.__dropdownWidth,this.__dropdown.height);
  121.          this.createObject("BoundingBox","mask",20);
  122.          this.mask._y = this.border_mc.height;
  123.          this.mask._width = this.__dropdownWidth;
  124.          this.mask._height = this.__dropdown.height;
  125.          this.mask._visible = false;
  126.          this.__dropdown.setMask(this.mask);
  127.       }
  128.       return this.__dropdown;
  129.    }
  130.    function setSize(w, h, noEvent)
  131.    {
  132.       super.setSize(w,h,noEvent);
  133.       this.__dropdownWidth = w;
  134.       this.__dropdown.rowHeight = h;
  135.       this.__dropdown.setSize(this.__dropdownWidth,this.__dropdown.height);
  136.    }
  137.    function setEditable(e)
  138.    {
  139.       super.setEditable(e);
  140.       if(e)
  141.       {
  142.          this.text_mc.setText("");
  143.       }
  144.       else
  145.       {
  146.          this.text_mc.setText(this.selectedLabel);
  147.       }
  148.    }
  149.    function get labels()
  150.    {
  151.       return this.__labels;
  152.    }
  153.    function set labels(lbls)
  154.    {
  155.       this.__labels = lbls;
  156.       this.setDataProvider(lbls);
  157.    }
  158.    function getLabelField()
  159.    {
  160.       return this.__labelField;
  161.    }
  162.    function get labelField()
  163.    {
  164.       return this.getLabelField();
  165.    }
  166.    function setLabelField(s)
  167.    {
  168.       this.__dropdown.labelField = this.__labelField = s;
  169.       this.text_mc.setText(this.selectedLabel);
  170.    }
  171.    function set labelField(s)
  172.    {
  173.       this.setLabelField(s);
  174.    }
  175.    function getLabelFunction()
  176.    {
  177.       return this.__labelFunction;
  178.    }
  179.    function get labelFunction()
  180.    {
  181.       return this.getLabelFunction();
  182.    }
  183.    function set labelFunction(f)
  184.    {
  185.       this.__dropdown.labelFunction = this.__labelFunction = f;
  186.       this.text_mc.setText(this.selectedLabel);
  187.    }
  188.    function setSelectedItem(v)
  189.    {
  190.       super.setSelectedItem(v);
  191.       this.__dropdown.selectedItem = v;
  192.       this.text_mc.setText(this.selectedLabel);
  193.    }
  194.    function setSelectedIndex(v)
  195.    {
  196.       super.setSelectedIndex(v);
  197.       this.__dropdown.selectedIndex = v;
  198.       this.text_mc.setText(this.selectedLabel);
  199.       this.dispatchValueChangedEvent(this.getValue());
  200.    }
  201.    function setRowCount(count)
  202.    {
  203.       if(isNaN(count))
  204.       {
  205.          return undefined;
  206.       }
  207.       this.__rowCount = count;
  208.       this.__dropdown.setRowCount(count);
  209.    }
  210.    function get rowCount()
  211.    {
  212.       return Math.max(1,Math.min(this.length,this.__rowCount));
  213.    }
  214.    function set rowCount(v)
  215.    {
  216.       this.setRowCount(v);
  217.    }
  218.    function setDropdownWidth(w)
  219.    {
  220.       this.__dropdownWidth = w;
  221.       this.__dropdown.setSize(w,this.__dropdown.height);
  222.    }
  223.    function get dropdownWidth()
  224.    {
  225.       return this.__dropdownWidth;
  226.    }
  227.    function set dropdownWidth(v)
  228.    {
  229.       this.setDropdownWidth(v);
  230.    }
  231.    function get dropdown()
  232.    {
  233.       return this.getDropdown();
  234.    }
  235.    function setDataProvider(dp)
  236.    {
  237.       super.setDataProvider(dp);
  238.       this.__dropdown.setDataProvider(dp);
  239.       if(!this._editable)
  240.       {
  241.          this.selectedIndex = 0;
  242.       }
  243.    }
  244.    function open()
  245.    {
  246.       this.displayDropdown(true);
  247.    }
  248.    function close()
  249.    {
  250.       this.displayDropdown(false);
  251.    }
  252.    function get selectedLabel()
  253.    {
  254.       var _loc2_ = this.selectedItem;
  255.       if(_loc2_ == undefined)
  256.       {
  257.          return "";
  258.       }
  259.       if(this.labelFunction != undefined)
  260.       {
  261.          return this.labelFunction(_loc2_);
  262.       }
  263.       if(typeof _loc2_ != "object")
  264.       {
  265.          return _loc2_;
  266.       }
  267.       if(_loc2_[this.labelField] != undefined)
  268.       {
  269.          return _loc2_[this.labelField];
  270.       }
  271.       if(_loc2_.label != undefined)
  272.       {
  273.          return _loc2_.label;
  274.       }
  275.       var _loc3_ = " ";
  276.       for(var _loc4_ in _loc2_)
  277.       {
  278.          if(_loc4_ != "__ID__")
  279.          {
  280.             _loc3_ = _loc2_[_loc4_] + ", " + _loc3_;
  281.          }
  282.       }
  283.       _loc3_ = _loc3_.substring(0,_loc3_.length - 3);
  284.       return _loc3_;
  285.    }
  286.    function hasDropdown()
  287.    {
  288.       return this.__dropdown != undefined && this.__dropdown.valueOf() != undefined;
  289.    }
  290.    function tweenEndShow(value)
  291.    {
  292.       this._y = value;
  293.       this.isPressed = true;
  294.    }
  295.    function tweenEndHide(value)
  296.    {
  297.       this._y = value;
  298.       this.visible = false;
  299.    }
  300.    function displayDropdown(show)
  301.    {
  302.       if(show == this._showingDropdown)
  303.       {
  304.          return undefined;
  305.       }
  306.       var _loc3_ = new Object();
  307.       _loc3_.x = 0;
  308.       _loc3_.y = this.height;
  309.       this.localToGlobal(_loc3_);
  310.       if(show)
  311.       {
  312.          this.getDropdown();
  313.          var _loc2_ = this.__dropdown;
  314.          _loc2_.isPressed = true;
  315.          _loc2_.rowCount = this.rowCount;
  316.          _loc2_.visible = show;
  317.          _loc2_.onTweenEnd = this.tweenEndShow;
  318.          var _loc5_ = undefined;
  319.          var _loc8_ = undefined;
  320.          if(_loc3_.y + _loc2_.height > Stage.height)
  321.          {
  322.             _loc5_ = _loc3_.y - this.height;
  323.             _loc8_ = _loc5_ - _loc2_.height;
  324.             this.mask._y = - _loc2_.height;
  325.          }
  326.          else
  327.          {
  328.             _loc5_ = _loc3_.y - _loc2_.height;
  329.             _loc8_ = _loc3_.y;
  330.             this.mask._y = this.border_mc.height;
  331.          }
  332.          var _loc7_ = _loc2_.selectedIndex;
  333.          if(_loc7_ == undefined)
  334.          {
  335.             _loc7_ = 0;
  336.          }
  337.          var _loc4_ = _loc2_.vPosition;
  338.          _loc4_ = _loc7_ - 1;
  339.          _loc4_ = Math.min(Math.max(_loc4_,0),_loc2_.length - _loc2_.rowCount);
  340.          _loc2_.vPosition = _loc4_;
  341.          _loc2_.move(_loc3_.x,_loc5_);
  342.          _loc2_.tween = new mx.effects.Tween(this.__dropdown,_loc5_,_loc8_,this.getStyle("openDuration"));
  343.       }
  344.       else
  345.       {
  346.          delete this.__dropdown.dragScrolling;
  347.          this.__dropdown.onTweenEnd = this.tweenEndHide;
  348.          this.__dropdown.tween = new mx.effects.Tween(this.__dropdown,this.__dropdown._y,_loc3_.y - this.__dropdown.height,this.getStyle("openDuration"));
  349.       }
  350.       var _loc9_ = this.getStyle("openEasing");
  351.       if(_loc9_ != undefined)
  352.       {
  353.          this.__dropdown.tween.easingEquation = _loc9_;
  354.       }
  355.       this._showingDropdown = show;
  356.       this.dispatchEvent({type:(!show ? "close" : "open"),target:this});
  357.    }
  358.    function onDownArrow()
  359.    {
  360.       this._parent.displayDropdown(!this._parent._showingDropdown);
  361.    }
  362.    function keyDown(e)
  363.    {
  364.       if(e.ctrlKey && e.code == 40)
  365.       {
  366.          this.displayDropdown(true);
  367.       }
  368.       else if(e.ctrlKey && e.code == 38)
  369.       {
  370.          this.displayDropdown(false);
  371.       }
  372.       else if(e.code == 27)
  373.       {
  374.          this.displayDropdown(false);
  375.       }
  376.       else if(e.code == 13)
  377.       {
  378.          if(this._showingDropdown)
  379.          {
  380.             this.selectedIndex = this.__dropdown.selectedIndex;
  381.             this.displayDropdown(false);
  382.          }
  383.       }
  384.       else if(!this._editable || e.code == 38 || e.code == 40 || e.code == 33 || e.code == 34)
  385.       {
  386.          this.selectedIndex = 0 + this.selectedIndex;
  387.          this.bInKeyDown = true;
  388.          var _loc3_ = this.dropdown;
  389.          _loc3_.keyDown(e);
  390.          this.bInKeyDown = false;
  391.          this.selectedIndex = this.__dropdown.selectedIndex;
  392.       }
  393.    }
  394.    function invalidateStyle(styleProp)
  395.    {
  396.       this.__dropdown.invalidateStyle(styleProp);
  397.       super.invalidateStyle(styleProp);
  398.    }
  399.    function changeTextStyleInChildren(styleProp)
  400.    {
  401.       if(this.dropdown.stylecache != undefined)
  402.       {
  403.          delete this.dropdown.stylecache[styleProp];
  404.          delete this.dropdown.stylecache.tf;
  405.       }
  406.       this.__dropdown.changeTextStyleInChildren(styleProp);
  407.       super.changeTextStyleInChildren(styleProp);
  408.    }
  409.    function changeColorStyleInChildren(sheetName, styleProp, newValue)
  410.    {
  411.       if(this.dropdown.stylecache != undefined)
  412.       {
  413.          delete this.dropdown.stylecache[styleProp];
  414.          delete this.dropdown.stylecache.tf;
  415.       }
  416.       this.__dropdown.changeColorStyleInChildren(sheetName,styleProp,newValue);
  417.       super.changeColorStyleInChildren(sheetName,styleProp,newValue);
  418.    }
  419.    function notifyStyleChangeInChildren(sheetName, styleProp, newValue)
  420.    {
  421.       if(this.dropdown.stylecache != undefined)
  422.       {
  423.          delete this.dropdown.stylecache[styleProp];
  424.          delete this.dropdown.stylecache.tf;
  425.       }
  426.       this.__dropdown.notifyStyleChangeInChildren(sheetName,styleProp,newValue);
  427.       super.notifyStyleChangeInChildren(sheetName,styleProp,newValue);
  428.    }
  429.    function onUnload()
  430.    {
  431.       this.__dropdown.removeMovieClip();
  432.    }
  433.    function _resizeHandler()
  434.    {
  435.       var _loc2_ = this.owner;
  436.       _loc2_.mask._width = this.width;
  437.       _loc2_.mask._height = this.height;
  438.    }
  439.    function _changeHandler(obj)
  440.    {
  441.       var _loc2_ = this.owner;
  442.       obj.target = _loc2_;
  443.       if(this != this.owner.text_mc)
  444.       {
  445.          _loc2_.selectedIndex = this.selectedIndex;
  446.          if(!_loc2_.bInKeyDown)
  447.          {
  448.             _loc2_.displayDropdown(false);
  449.          }
  450.       }
  451.       _loc2_.dispatchEvent(obj);
  452.    }
  453.    function _scrollHandler(obj)
  454.    {
  455.       var _loc2_ = this.owner;
  456.       obj.target = _loc2_;
  457.       _loc2_.dispatchEvent(obj);
  458.    }
  459.    function _itemRollOverHandler(obj)
  460.    {
  461.       var _loc2_ = this.owner;
  462.       obj.target = _loc2_;
  463.       _loc2_.dispatchEvent(obj);
  464.    }
  465.    function _itemRollOutHandler(obj)
  466.    {
  467.       var _loc2_ = this.owner;
  468.       obj.target = _loc2_;
  469.       _loc2_.dispatchEvent(obj);
  470.    }
  471.    function modelChanged(eventObj)
  472.    {
  473.       super.modelChanged(eventObj);
  474.       if(0 == this.__dataProvider.length)
  475.       {
  476.          this.text_mc.setText("");
  477.          delete this.selected;
  478.       }
  479.       else if(this.__dataProvider.length == eventObj.lastItem - eventObj.firstItem + 1 && eventObj.eventName == "addItems")
  480.       {
  481.          this.selectedIndex = 0;
  482.       }
  483.    }
  484. }
  485.